<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 从数组中移除最大元素和最小元素 -->
    <script>
      function minimumDeletions(nums) {
        let [max, min] = [Math.max(...nums), Math.min(...nums)]
        let [maxPos, minPos] = [nums.indexOf(max), nums.indexOf(min)]
        let len = nums.length
        let [left, right] = [Math.min(minPos, maxPos), Math.max(maxPos, minPos)]
        return Math.min(right + 1, len - left, 1 + left + len - right)
      }
      console.log(minimumDeletions([2, 10, 7, 5, 4, 1, 8, 6]))
    </script>
  </body>
</html>
